import 'package:flutter/material.dart';
import 'package:flutter_base/user/app_user_manager.dart';
import 'package:get/get.dart';
import 'package:flutter_base/base/controller/base_controller.dart';

class MainLogic extends GetxController with GetSingleTickerProviderStateMixin {
  late PageController pageController;
  int currentIndex = 0;
  
  @override
  void onInit() {
    super.onInit();
    // 检查是否有传入的索引参数
    if (Get.arguments != null && Get.arguments is Map) {
      final args = Get.arguments as Map;
      if (args.containsKey('index')) {
        currentIndex = args['index'];
      }
    }
    pageController = PageController(initialPage: currentIndex, keepPage: true);
  }
  
  @override
  void onClose() {
    pageController.dispose();
    super.onClose();
  }
  
  // 切换底部标签
  void switchTab(int index) {
    if (currentIndex == index) return;
    currentIndex = index;
    pageController.jumpToPage(index);
    update();

    if (index == 2) {
      AppUserManager().refreshUserInfo();
    }

  }
}